<template>

  <BasicDrawer v-bind="$attrs" title="" @register="registerDrawer" width="1800px">
    <BasicTable @register="registerTable">

      <template v-slot:bodyCell="{ column, record, index, text }">
         <template v-if="column.dataIndex==='quotationFile'">
          <!--文件字段回显插槽-->
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" preIcon="ant-design:download-outlined" size="small"
                    @click="handleViewFile(text)">查看</a-button>
        </template>

      </template>

    </BasicTable>
  </BasicDrawer>
</template>

<script lang="ts" name="crm-cProjectQuote" setup>
  import { ref, unref,reactive } from 'vue';
   import ViewFileDetail from "@/components/FileView/ViewFileDetail.vue";
  import { BasicDrawer,useDrawerInner } from '/@/components/Drawer';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { BasicTable } from '/@/components/Table';
  import { useDesign } from '/@/hooks/web/useDesign';
  import { list} from './CProjectQuote.api';
  import {BasicColumn} from '/@/components/Table';
  import { mapTableTotalSummary } from '@/utils/common/compUtils';
  import { downloadFile } from "@/utils/common/renderUtils";
  import CProjectQuoteModal from "./components/CProjectQuoteModal.vue";


  let additionalId = '';
  const registerModal = ref();

  const formRef = ref();
  // 从子组件获取 viewFileDetail 方法
  const viewFileDetail = ref();
  const viewFileDetailRef = ref();
  // 在 table 的插槽中使用 viewFileDetail 方法
  function handleViewFile(url) {

    viewFileDetail.value(url);
  }

  //接收id
  const [registerDrawer] = useDrawerInner(async (data) => {
    additionalId = data.id
	//刷新
	reload();
  });
 const columns: BasicColumn[] = [
 /*  {
    title: '项目',
    align: "center", resizable: true,
    dataIndex: 'projectId_dictText'
  },
  {
    title: '子项目',
    align: "center",
    resizable: true,
    dataIndex: 'subProjectId_dictText'
  },*/
      {
    title: '报价人',
    align: "center",
    resizable: true,
    dataIndex: 'userId_dictText'
  },
    {
    title: '项目需求',
    align: "center",
    resizable: true,
    dataIndex: 'additionalId_dictText'
  },
  {
    title: '合同价',
    align: "center", resizable: true,
    dataIndex: 'contractPrice'
  },
  {
    title: '含税价格',
    align: "center", resizable: true,
    dataIndex: 'taxInclusivePrice'
  },
  {
    title: '税率',
    align: "center", resizable: true,
    dataIndex: 'taxRate'
  },
  {
    title: '报价文件',
    align: "center", resizable: true,
    dataIndex: 'quotationFile',
  },
  {
    title: '状态',
    align: "center", resizable: true,
    dataIndex: 'status_dictText'
  },
];
  //注册table数据
  const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
    tableProps: {
      title: '报价记录',
      api: list,
      columns,
      canResize:false,
      actionColumn: {
        width: 1,
        fixed: 'right',
      },
      useSearchForm: false,
      showSummary: true,
      //summaryFunc: onSummary,
        beforeFetch: async (params) => {
        const defaultParams = { 'additionalId': additionalId };
          return Object.assign(params, defaultParams);
        },
      afterFetch: (data) => {
        return data;
      },
    },
  });
  
  const [registerTable, { reload, collapseAll, updateTableDataRecord, findTableDataRecord, getDataSource },
  { rowSelection, selectedRowKeys }] = tableContext;
  const labelCol = reactive({
    xs: 24,
    sm: 4,
    xl: 6,
    xxl: 4
  });
  const wrapperCol = reactive({
    xs: 24,
    sm: 20,
  });
//列表数据
  function onSummary(tableData: Recordable[]) {
    // 可用工具方法自动计算合计
    const totals = mapTableTotalSummary(tableData, ['amount']);
    return [
      totals,
      {
        totalContractor: totals
      },
    ];
  }

    /**
   * 编辑事件
   */
  function handleEdit(record: Recordable) {

    registerModal.value.add(record);
  }
  /**
   * 成功回调
   */
  function handleSuccess() {
    (selectedRowKeys.value = []) && reload();
  }
</script>
<style scoped lang="less">
  @prefix-cls: ~'@{namespace}-row-invalid';

  :deep(.@{prefix-cls}) {
    background: #f4f4f4;
    color: #bababa;
  }
</style>
